package com.leyou.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.leyou.vo.SpecParamVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.leyou.entity.SpecParamEntity;
import com.leyou.service.SpecParamService;

import com.leyou.api.R;



/**
 * 规格参数组下的参数名
 *
 * @author Daifeng
 * @email 2661184062@qq.com
 * @date 2020-12-25 16:44:46
 */
@RestController
@RequestMapping("/specparams")
public class SpecParamController {

    @Autowired
    private SpecParamService specParamService;

    /**
     * 根据分类id查询属性信息
     * @param cid
     * @return
     */
    @GetMapping("/cid")
    private R listByCid(@RequestParam(defaultValue = "0") Long cid){
        List<SpecParamEntity> paramEntities =  specParamService.listByCid(cid);
        return R.ok().put("data",paramEntities);
    }


    /**
     * 根据分组id查询属性信息
     * @param gid
     * @return
     */
    @GetMapping("/list/{gid}")
    private R listByGid(@PathVariable Long gid){
        List<SpecParamEntity> paramEntities =  specParamService.listByGid(gid);
        return R.ok().put("data",paramEntities);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpecParamEntity specParam = specParamService.getById(id);

        return R.ok().put("specParam", specParam);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SpecParamVo specParam){
		specParamService.saveSpec(specParam);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/save")
    public R update(@RequestBody SpecParamVo specParam){
		specParamService.saveSpec(specParam);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
		specParamService.removeById(id);
        return R.ok();
    }

}
